package com.itheima;

public class Test4 {
    public static void main(String[] args) {
        //完成数字加密后的开发
        System.out.println("加密后的结果为"+encrypt(1983));
    }
    public static String encrypt(int number){
        //num =1983
        int[] numbers =split(number);

        for (int i = 0; i < numbers.length; i++) {
            numbers[i] = (numbers[i]+5) % 10;
        }
        //反转数组
        reverse(numbers);

        String data = "";
        for (int i = 0; i < numbers.length; i++) {
            data += numbers[i];
        }
        return data;
    }

    public static void reverse(int[] numbers) {
        for (int i = 0,j=numbers.length-1; i < j; i++,j--) {
            int temp = numbers[j];
            numbers[j] = numbers[i];
            numbers[i] = temp;
        }
    }

    public static int[] split(int num) {
        int[] numbers = new int[4];
        numbers[0] = num / 1000;
        numbers[1] = num % 1000 / 100;
        numbers[2] = num % 100 / 10;
        numbers[3] = num % 10;
        //返回数组
        return numbers;
    }
}
